package com.xjc.business.controller.classadmin;

import com.xjc.business.entity.po.classadmin.ClassActivityPo;
import com.xjc.business.entity.vo.PageVo;
import com.xjc.business.entity.vo.classadmin.ClassActivityVo;
import com.xjc.business.entity.vo.ActivityRankVo;
import com.xjc.business.service.ActivitiesService;
import com.xjc.business.service.ActivityJoinListsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-02-10 8:34
 */
@RestController
@RequestMapping("/class_admin/activity")
public class ClassActivityController {

    @Autowired
    ActivitiesService activitiesService;

    @Autowired
    ActivityJoinListsService activityJoinListsService;

    /**
     * 获取宿舍评优活动列表
     * @param pageSize 每页显示条数
     * @param currentPage 当前页
     * @param classAdminId 辅导员id
     * @param status 状态
     * @return Result
     */
    @GetMapping("/page/{pageSize}/{currentPage}")
    public Result<PageVo<ClassActivityVo>> getActivityPage(
            @PathVariable(value = "pageSize",required = false) Integer pageSize,
            @PathVariable(value = "currentPage",required = false) Integer currentPage,
            Integer classAdminId,
            Integer status
    ){
        if(pageSize == null || pageSize <= 0){
            pageSize = 10;
        }
        if(currentPage == null || currentPage <= 0){
            currentPage = 1;
        }

        if(status == null){
            status = -1;
        }

        if(classAdminId == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return activitiesService.getActivityPage(pageSize,currentPage,classAdminId,status);
    }

    /**
     * 添加宿舍评优活动
     * @param classActivityPo 宿舍评优活动
     * @return Result
     */
    @PostMapping("/add")
    public Result<String> addActivity(@RequestBody(required = false)ClassActivityPo classActivityPo){
        if(classActivityPo == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return activitiesService.addActivity(classActivityPo);
    }

    /**
     * 获取宿舍评优内容
     * @param id 宿舍评优id
     * @return 内容
     */
    @RequestMapping("/desc/{id}")
    public Result<String> getActivityDesc(@PathVariable(value = "id",required = false) Integer id){
        return Result.okWithData(activitiesService.getById(id).getContent());
    }

    /**
     * 获取宿舍评优活动排名列表-前十
     * @param id 宿舍评优id
     * @return Result
     */
    @GetMapping("/rankList/{id}")
    public Result<List<ActivityRankVo>> getActivityRankList(@PathVariable(value = "id",required = false) Integer id){
        if(id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return activityJoinListsService.getActivityRankList(id);
    }
}